/*
 * @lc app=leetcode id=169 lang=cpp
 *
 * [169] Majority Element
 */
class Solution {
public:
    int majorityElement(vector<int>& nums) {
        int last;
        int cnt = 0;
        for (auto n : nums) {
            if (cnt == 0) {
                last = n;
                cnt++;
            } else if (last == n) {
                cnt++;
            } else {
                cnt--;
            }
        }
        return last;
        
    }
};

